<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">评价管理</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">评价列表</div>
                    <div class="panel-body inner-body">
                        <div class="main-box-search">
                            <form method="get" name="from1"  id="searchForm"  >
                                <div class="search-row">
                                    <div class="col-lg-3 col-md-6" style=" margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" name="accountId" id="accountId"
                                               placeholder="请输入用户ID">
                                    </div>
                                    <div class="col-lg-2 col-md-6" style="margin-bottom:15px; padding-left:0px;">
                                        <select class="form-control" id="productSellerId">
                                        	<option value="">全部</option>
                                        	<c:forEach var="item" items="${productSellerList}" varStatus="status">
						                    	<option value="${item.productSellerId}">${item.productSellerName}</option>
						                    </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <a class="btn btn-primary" href="${webPath}toDiscussAdd"
                      style="margin-left:15px;margin-bottom:30px;">添加评价</a>
                            </form>
                        </div>
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
	                                <tr>
	                                	<th class="text-center" style="width:3%;">ID</th>
	                                	<th class="text-center" style="width:8%">用户ID</th>
	                                	<th class="text-center" style="width:8%">用户昵称</th>
	                                	<th class="text-center" style="width:6%">用户头像</th>
	                                    <th class="text-center" style="width:16%">评价内容</th>
	                                    <th class="text-center" style="width:8%;">创建时间</th>
	                                    <th class="text-center" style="width:8%;">更新时间</th>
	                                    <th class="text-center" style="width:5%;">状态</th>
	                                    <th class="text-center" style="width:12%;">操作</th>
	                                </tr>
                                </thead>
                                <tbody id="discussList">
                                
                                </tbody>
                            </table>
                        </div>
                        <div class="modal fade" id="delcfmModel">
                            <div class="modal-dialog modal-sm">
                                <div class="modal-content message_align">
                                    <div class="modal-header">
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        <h4 class="modal-title">提示信息</h4>
                                    </div>
                                    <div class="modal-body">
                                        <p>您确认要删除吗？</p>
                                    </div>
                                    <div class="modal-footer">
                                        <input id="url" type="hidden">
                                        <button class="btn btn-default" type="button" data-dismiss="modal">取消</button>
                                        <a class="btn btn-danger" onclick="pro_delete()" data-dismiss="modal">确定</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="box">
							<div id="pagination3" class="page fl"></div>
						</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:inline="javascript">
	searchCase(0,1);
	
	$('#searchForm').change(function(e) {
		searchCase(1,1);
	})
	
	//搜索
	function searchCase(flag,page) {
		
		var accountId = "";
		var productId = "";
		var orderId = "";
		var productSellerId = "";
		if(flag == 1){
			accountId = $("#accountId").val();
			productId = $("#productId").val();
			orderId = $("#orderId").val();
			productSellerId=$("#productSellerId option:selected").val();  //获取选中的项
		}
		
		var pageSize= 10;
		var baseURL = "${webPath}/discuss/list";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"accountId":accountId,
	        	"productSellerId":productSellerId,
	            "page": page,
	            "pageSize": pageSize
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            alert(result.body.description)
	            $("#discussList").empty();
	        } else {
	        	$("#discussList").empty();
	        	var list = result.body.list;
	        	console.log(list);
	        	var count = result.body.count;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<tr>';
	        		str += '	<td class="text-center">'+list[i].id+'</td>';
	        		str += '	<td class="text-center">'+list[i].accountId+'</td>';
	        		str += '	<td class="text-center">'+list[i].nickname+'</td>';
	        		str += '	<td class="coverImg"><img class="center-block" src="'+list[i].image+'"></td>';
	        		str += '	<td class="text-center">'+list[i].content+'</td>';
	        		str += '	<td class="text-center">'+list[i].createTime+'</td>';
	        		str += '	<td class="text-center">'+list[i].updateTime+'</td>';
	        		str += '	<td class="text-center">'+list[i].statusValue+'</td>';
	        		str += '	<td class="text-center">';
	        		str += '		<a class="btn btn-default" href="${webPath}toDiscussEdit/'+list[i].id+'">编辑</a>';
	        		str += '	</td>';
	        		str += '</tr>';
	        	}
	        	$("#discussList").append(str);
	        	
	        	var currentPage = page;
	        	var sumPage = Math.ceil(count/pageSize);
	        	
	        	$("#pagination3").pagination({
					currentPage: currentPage,
					totalPage: sumPage,
					isShow: true,
					count: 10,
					homePageText: "首页",
					endPageText: "尾页",
					prevPageText: "上一页",
					nextPageText: "下一页",
					callback: function(current) {
						searchCase(1,current);
					}
				});
	        }
	    })
	}


	
	var discussIdCurrent = "";
	
    function delcfm(discussId) {
        $('#delcfmModel').modal();
        discussIdCurrent = discussId;
    }
    var pro_delete = function () {
    	var baseURL = "${webPath}/discuss/delete";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"discussId": discussIdCurrent
	        }
	    }
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                alert('删除成功')
            } else {
                alert(result.body.description)
            }
        })
    }

    $(document).ready(function () {
        var lenth = $('#product_list tr').length;
        if (lenth == 0) {
            $('tbody#menu_list').append('<tr id="empty_menu"><td colspan="7" class="no-menu text-center">没有评价信息！</td></tr>');
        } else {
            $('#empty_menu').hide();
        }
    })

</script>
</body>
</html>
